package com.itheima.test;

import org.elasticsearch.client.IndicesClient;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;

@SpringBootTest
public class testEasticSearch {
    @Autowired
    private RestHighLevelClient client;

@Test
    public void testCreateIndex() throws IOException {
        //System.out.println(client);
    //1.使用client获取操作索引对象
    IndicesClient client = this.client.indices();

    //2.具体操作获取返回值,RequestOptions主要用来设置一些请求头信息，一般使用默认值

    //2.1 设置索引名称
    CreateIndexRequest createIndexRequest = new CreateIndexRequest("itheima");
    CreateIndexResponse createIndexResponse = client.create(createIndexRequest, RequestOptions.DEFAULT);
    //3.根据返回值判断结果
    System.out.println(createIndexResponse.isAcknowledged());

    }
}
